#include "SRCommandNamedArgument.h"
#include "SRCommand.h"
#include <QDebug>


SRCommandNamedArgument::SRCommandNamedArgument()
{
	argumentValues = QStringList();
}


SRCommandNamedArgument::SRCommandNamedArgument(QString name, QString value)
{
	SRCommandNamedArgument();
	argumentName = name;
	argumentValues.append(value);
	qDebug() << "STRING";
}


SRCommandNamedArgument::SRCommandNamedArgument(QString name, QStringList values)
{
	SRCommandNamedArgument();
	argumentName = name;
	argumentValues = values;
	qDebug() << "STRINGLIST";
}


SRCommandNamedArgument::SRCommandNamedArgument(QStringList values)
{
	SRCommandNamedArgument();
	argumentValues = values;
}


SRCommandNamedArgument::SRCommandNamedArgument(QString s)
{
	SRCommandNamedArgument();
	QStringList splitted = s.split(SRCommand::commandArgumentValueSeparator);

	if(splitted.size() ==0 ) return;

	// extract and store argument name
	QString name = splitted.at(0);
	splitted.removeFirst();

	// call constructor with the extracted name and(possibly) values
	SRCommandNamedArgument(name, splitted);

}


SRCommandNamedArgument::~SRCommandNamedArgument()
{
	// TODO
}


QString SRCommandNamedArgument::getName()
{
	return argumentName;
}


QStringList SRCommandNamedArgument::getValues()
{
	return argumentValues;
}


void SRCommandNamedArgument::setName(QString name)
{
	argumentName = name;
}


void SRCommandNamedArgument::setValues(QStringList values)
{
	argumentValues = values;
}


void SRCommandNamedArgument::addValue(QString value)
{
	argumentValues.append(value);
}


QString SRCommandNamedArgument::toString()
{
	QString stringRepresentation;

	stringRepresentation += argumentName;
	stringRepresentation += SRCommand::commandArgumentNameSeparator;

	for(int i=0; i<argumentValues.size(); i++)
	{
		stringRepresentation += argumentValues.at(i);
		if(i != argumentValues.size()-1) // append value separator after all values except the last one
		{
			stringRepresentation += SRCommand::commandArgumentValueSeparator;
		}
	}

	// end of argument string. append the argument separator
	stringRepresentation += SRCommand::commandArgumentSeparator;

	return stringRepresentation;
}
